//
//  UIView+IBInsepectable.swift
//  Sina15
//
//  Created by 盼 on 16/4/6.
//  Copyright © 2016年 pan. All rights reserved.
//

import UIKit

//分类里面不能有存储性质的属性
extension UIView {
    
      //设置cornerRadius
    @IBInspectable var cornerRadius:CGFloat {
            
            //获取layer.cornerRadius
            get {
                return layer.cornerRadius
            }
            
            //设置layer.cornerRadius
            set {
                
                layer.cornerRadius = newValue
                
                if newValue>0 {
                    layer.masksToBounds = true
                }else{
                layer.masksToBounds = false
                }
            }
    }
    
    
    @IBInspectable var border:CGFloat {
        
        //获取border
        get {
          return  layer.borderWidth
        }
        
        //设置border
        set {
            layer.borderWidth = newValue
        }
    }
    
    
    @IBInspectable var borderColor:UIColor? {
        
        //获取边框颜色
        get {
            //有值返回
            if let c = layer.borderColor {
                
                return UIColor(CGColor: c)
            }
            //否则返回空
            return nil
        }
        
        //设置边框颜色
        set {
            
            layer.borderColor = newValue!.CGColor
        }
    }
   
}

